from django.db import models
from User.models import *
from goods.models import *
# Create your models here.
class Order(models.Model):
    out_trade_num = models.UUIDField(auto_created=True,unique=True)
    order_num = models.CharField(max_length=50)
    address = models.ForeignKey(Address,on_delete=models.CASCADE)
    user = models.ForeignKey(User,on_delete=models.CASCADE)
    trade_no = models.CharField(max_length=120,default='')
    status = models.CharField(max_length=20,default='待付款')
    payway = models.CharField(max_length=20,default='alipay')
class OrderItem(models.Model):
    goodsid = models.IntegerField()
    sizeid = models.IntegerField()
    colorid = models.IntegerField()
    count = models.PositiveIntegerField()
    order = models.ForeignKey(Order,on_delete=models.CASCADE)
    def goods(self):
        return Goods.objects.get(id=self.goodsid)

    def total_price(self):
        return int(self.count) * float(self.goods().price)

